package controlador;

import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.ServicoService;

import modelo.Servico;

/**
 * Servlet para efetuar a consulta do fornecedor escolhido para a vaga
 */
public class ServletConsultaFornecedorEscolhido extends HttpServlet {
	private static final long serialVersionUID = -5152741970787522090L;

	public ServletConsultaFornecedorEscolhido() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		HttpSession session = request.getSession(true);
		try {
			String usuario = request.getParameter("nomeUsuario");
			Collection<Servico> servicos = new LinkedList<Servico>();
			String tituloServico     = "";
			String nomeUsuario       = "";
			String areaAtuacao       = "";
			String formaPagamento    = "";
			String prazoProjeto      = "";
			String abatimentoAtrazo  = "";
			String descricaoServico  = "";
			String fornecedorServico = "";
			
			ServicoService ser = new ServicoService();
			LinkedList<String> serv = (LinkedList<String>) ser.consultarServicoFornecedorEscolhido(usuario);

			for (int i = 0; i < serv.size(); i++) {
				tituloServico = serv.get(i);
				i++;
				nomeUsuario = serv.get(i);
				i++;
				areaAtuacao = serv.get(i);
				i++;
				formaPagamento = serv.get(i);
				i++;
				prazoProjeto = serv.get(i);
				i++;
				abatimentoAtrazo = serv.get(i);
				i++;
				descricaoServico = serv.get(i);
				i++;
				fornecedorServico = serv.get(i);

				Servico servico = new Servico(tituloServico, nomeUsuario,areaAtuacao, formaPagamento, prazoProjeto,abatimentoAtrazo, descricaoServico, fornecedorServico);
				servicos.add(servico);
			}
		
			
			
			session.setAttribute("listaServicos", servicos);
			response.sendRedirect("paginasFornecedor/paginaFornecedorEscolhido.jsp");
		} catch (Exception e) {

		}
		
	}

}
